//获取应用实例
const app = getApp();
// 引入AES.js
var baseJs = require("../../common/base.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    uid: "",
    code: "",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      uid: wx.getStorageSync('uid'),
    })
  },

  // 兑换码
  exchangeCode: function(e) {
    console.log(e);
    this.setData({
      code: e.detail.value,
    })
  },
  // 提交
  sureTap: function() {
    var that = this;
    var code = this.data.code;
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=FinishedExchangeOrder&ConsumerNumber=" + code),
      success: function(res) {
        var json = JSON.parse(baseJs.decryUrl(res.data));
        if (json.ResultFlag == 1) {
          wx.showToast({
            title: json.ResultMsg,
            icon: 'none',
            duration: 2000
          });
          setTimeout(function() {
            wx.navigateBack({
              delta: 1
            })
          }, 500)
        } else {
          wx.showToast({
            title: json.ResultMsg,
            icon: 'none',
            duration: 3000
          });
        }
      }
    })
  },
})